﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SpaceSquirrel.SpecialLevelStuff
{
	public class GravityCorePlacement : SpecialLevel
	{
		private int col;
		private int row;
		private bool done;

		public GravityCorePlacement(PlayScene scene)
			: base(scene)
		{
			this.HasPostInit = true;
			this.HasUpdate = true;
			this.col = 11;
			this.row = 9;
			this.done = false;
		}

		public override void Update()
		{
			Sprite player = this.scene.Player;
			int tx = player.x / 16;
			int ty = player.y / 16;

			if (tx == this.col && Math.Abs(ty - this.row) < 2 && !this.done)
			{
				this.AddGDevice(true);
			}
		}

		public override void PostInit()
		{
			if (this.context.Gravity)
			{
				this.AddGDevice(false);
			}
		}

		public void AddGDevice(bool showDialog)
		{
			this.done = true;
			this.context.Gravity = true;
			Sprite gd = new Sprite("gravity_device", this.col * 16, this.row * 16);
			gd.floats = true;
			this.scene.Sprites.Add(gd);
			if (showDialog)
			{
				this.scene.Next = new DialogScene(this.scene, "GravityDone", true, false, false);			}
		}
	}
}
